﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

using WXWorkSvc.Common.Data;

namespace WXWorkSvc.Common.Models;
public static class SqlServerLoggerFactoryExtension
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="builder"></param>
    /// <param name="loggerConnectionString">数据库连接字符串</param>
    /// <param name="createTable">是否创建日志表</param>
    /// <param name="loggerTableName">日志表表名称</param>
    /// <returns></returns>
    public static ILoggingBuilder AddSqlServerLogger(this ILoggingBuilder builder)
    {

        builder.ClearProviders();
        //builder.Services.AddHostedService<SqlServerLoggerHostedService>();
        builder.Services.AddSingleton<SqlServerLoggerProcessor>();
        builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, SqlServerLoggerProvider>());
        return builder;
    }


}

